#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""手动封装sql相关操作
"""
import pymysql

from lj_tool import tool_cache


class ConnBean():
    def __init__(self, host, user, db, database) -> None:
        self.host = host
        self.user = user
        self.db = db
        self.database = database
        self.charset = 'utf8mb4'
        self.cursorclass = pymysql.cursors.DictCursor


class LJPool():

    @tool_cache.lj_wrapper_cache("lj_orm_init_db", 60 * 60 * 24 * 30)
    def __init__(self, conn_bean: ConnBean):
        self.db = pymysql.connect(**conn_bean)

    def __enter__(self):
        self.curr = self.db.cursor()
        return self.curr

    def __exit__(self, exc_type, exc_value, traceback):
        if not exc_type:
            self.db.commit()
        else:
            self.db.rollback()
        # # 关闭session:
        self.curr.close()
        return False


class LJOrm():
    def __init__(self, conn_bean: ConnBean):
        self.lj_pool = LJPool(conn_bean)

    def select(self, ):
        pass
